/**
 * Copyright 2017 orivil Authors. All rights reserved.
 * Use of this source code is governed by a MIT-style
 * license that can be found at https://mit-license.org.
 */

package swagger

import (
	"reflect"
	"gitee.com/tugoer/param"
)

type MimeType string

type dataTypeEncoder interface {
	setDataType(typ, format string, items *Items)
}

func setDataType(kind reflect.Kind, setter dataTypeEncoder) {

	switch kind {
	case param.String:
		setter.setDataType("string", "", nil)
	case param.Int, param.Int32:
		setter.setDataType("integer", "int32", nil)
	case param.Int64:
		setter.setDataType("integer", "int64", nil)
	case param.Float32:
		setter.setDataType("number", "float", nil)
	case param.Float64:
		setter.setDataType("number", "double", nil)
	case param.Bool:
		setter.setDataType("boolean", "", nil)
	case param.File:
		// setter.setDataType("string", "binary", nil)  // OpenAPI3.0
		setter.setDataType("file", "", nil) // OpenAPI2.0
	case param.TextUnmarshaler:
		setter.setDataType("string", "date-time", nil)
	case param.SliceString:
		setter.setDataType("array", "", &Items{Type: "string"})
	case param.SliceInt, param.SliceInt32:
		setter.setDataType("array", "", &Items{Type: "integer", Format: "int32"})
	case param.SliceInt64:
		setter.setDataType("array", "", &Items{Type: "integer", Format: "int64"})
	case param.SliceFloat32:
		setter.setDataType("array", "", &Items{Type: "number", Format: "float"})
	case param.SliceFloat64:
		setter.setDataType("array", "", &Items{Type: "number", Format: "double"})
	case param.SliceBool:
		setter.setDataType("array", "", &Items{Type: "boolean"})
	case param.Unsupported:
		setter.setDataType("unsupported", "", nil)
	case param.UnsupportedSlice:
		setter.setDataType("array", "", &Items{Type: "unsupported"})
	default:
		setter.setDataType("unsupported", "", nil)
	}
}
